package MaratImpl;

import java.io.FileWriter;
import java.io.IOException;

import org.omg.CORBA.ORB;
import org.omg.CORBA.ORBPackage.InvalidName;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;
import org.omg.PortableServer.POAManagerPackage.AdapterInactive;
import org.omg.PortableServer.POAPackage.ServantNotActive;
import org.omg.PortableServer.POAPackage.WrongPolicy;

public class Server {
	
	public static void main(String[] args)  {
		ORB orb = ORB.init(args, null);
		POA rootpoa = null;
        try {
	        rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
        } catch (InvalidName e) {
	        // TODO Auto-generated catch block
	        e.printStackTrace();
        }
		try {
	        rootpoa.the_POAManager().activate();
        } catch (AdapterInactive e) {
	        // TODO Auto-generated catch block
	        e.printStackTrace();
        }

		MarathonImpl c = new MarathonImpl();

		org.omg.CORBA.Object ref = null;
        try {
	        ref = rootpoa.servant_to_reference(c);
        } catch (ServantNotActive | WrongPolicy e) {
	        // TODO Auto-generated catch block
	        e.printStackTrace();
        }      
		      
		String IORenString = orb.object_to_string(ref);
		FileWriter fw = null;
        try {
	        fw = new FileWriter("FicPourIOR");
        } catch (IOException e) {
	        // TODO Auto-generated catch block
	        e.printStackTrace();
        }
		try {
	        fw.write(IORenString);
        } catch (IOException e) {
	        // TODO Auto-generated catch block
	        e.printStackTrace();
        }
		try {
	        fw.close();
        } catch (IOException e) {
	        // TODO Auto-generated catch block
	        e.printStackTrace();
        }
		System.out.println("server ready...");
		orb.run();
		
	}
	
}
